<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repos\CategoryRepo;
use App\Repos\BillboardRepo;
use Log,Session;
use App\Services\RedisService;

class IndexController extends Controller
{
    public function index(Request $request)
    {
    	
    	
       
        $where =  [];
        // if($request->cate_id) {
        //     $where['category_id'] = $request->cate_id;
        // }
        $list = BillboardRepo::get($where);
    	return view('admin.index',compact('list'));
    }

    /**
     * 更新广告牌geo
     */
    public function refreshGeo(Request $request)
    {
        
        $list   = BillboardRepo::get();
        foreach ($list as $k => $v) {
           if(empty($v->lnglat)) continue;
           $lnglat = explode(',', $v->lnglat);
           RedisService::geoadd($lnglat[0],$lnglat[1],$v->id);
        }
        return back();       

    }

    /**
     * 更新广告牌信息缓存
     */
    public function refreshBillboard(Request $request)
    {
        $list   = BillboardRepo::get();
        foreach ($list as $k => $v) {
           $key = 'ad:board:'.$v->id;  
           RedisService::set($key,$v->toJson());
        }
        return back(); 
    }
}
